class CreateMessages < ActiveRecord::Migration
  def self.up
    create_table :messages, :force => true do |t|
      t.column :root_id, :integer
      t.column :parent_id, :integer
      t.column :lft, :integer
      t.column :rgt, :integer
      t.column :depth, :integer
      t.column :subject, :string
      t.column :body, :text
      t.column :user_id, :integer
      t.column :updated_at, :timestamp
      t.column :created_at, :timestamp
      t.column :author_id, :integer
      t.column :category_id, :integer    
    end
    execute " ALTER TABLE `messages` CHANGE `depth` `depth` INT( 11 ) NOT NULL DEFAULT '0' "
    execute "  ALTER TABLE `messages` CHANGE `parent_id` `parent_id` INT( 11 ) NOT NULL DEFAULT '0' "
    execute " ALTER TABLE `messages` CHANGE `lft` `lft` INT( 11 ) NOT NULL DEFAULT '0' " 
    execute " ALTER TABLE `messages` CHANGE `rgt` `rgt` INT( 11 ) NOT NULL DEFAULT '0' "
  end

  def self.down
    drop_table :messages
  end
end
